class Solution {
public:
    vector<int> largestValues(TreeNode* root) {
        vector<int>arr;
        queue<TreeNode*>q;
        q.push(root);
        if(root==NULL){return {};}
        while(!q.empty()){
            int maxnum=INT_MIN;
            int len=q.size();
            for(int i=0;i<len;i++){
                root=q.front();
                q.pop();
                maxnum=max(maxnum,root->val);
                if(root->left){q.push(root->left);}
                if(root->right){q.push(root->right);}
            }
            arr.push_back(maxnum);
        }
        return arr;
    }
};